package com.csd.adapter;

import java.util.List;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AnimationSet;
import android.view.animation.TranslateAnimation;
import android.widget.BaseAdapter;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.csd.activity.CsdApplication;
import com.csd.activity.EnterpriseApplayActivity;
import com.csd.activity.EnterpriseOrderActivity;
import com.csd.activity.PersonalDetailActivity;
import com.csd.activity.R;
import com.csd.bean.EnterpriseOrder;
import com.csd.fragment.EnterpriseAllFragment;

public class EnterpriseAllAdapter extends BaseAdapter {

	List<EnterpriseOrder> list;
	Context context;

	public EnterpriseAllAdapter(List<EnterpriseOrder> list, Context context) {
		super();
		this.list = list;
		this.context = context;
	}

	@Override
	public int getCount() {
		// TODO Auto-generated method stub
		return list.size();
	}

	@Override
	public Object getItem(int position) {
		// TODO Auto-generated method stub
		return list.get(position);
	}

	@Override
	public long getItemId(int position) {
		// TODO Auto-generated method stub
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		EnterpriseOrder order = list.get(position);
		View v = null;
		if (order.getState() == 0) {
			v = LayoutInflater.from(context)
					.inflate(R.layout.applay_item, null);
			TextView orderId = (TextView) v.findViewById(R.id.orderid);
			TextView purposer = (TextView) v.findViewById(R.id.purpose);
			TextView carType = (TextView) v.findViewById(R.id.cartype);
			TextView time = (TextView) v.findViewById(R.id.time);
			TextView applayTime = (TextView) v.findViewById(R.id.applaytime);
			Button bt_cancle = (Button) v.findViewById(R.id.canle_order);
			Button bt_change = (Button) v.findViewById(R.id.change);
			bt_change.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(context,
							EnterpriseApplayActivity.class);
					context.startActivity(intent);
					((Activity) context).finish();
				}
			});
			bt_cancle.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					EnterpriseAllFragment.tv_cancle.setText("确定要取消申请单吗");
					CsdApplication.showContent(EnterpriseAllFragment.ll_cancle, context);
				}
			});
			orderId.setText("申请单：SQ-000" + order.getOrderId());
			purposer.setText(order.getPurpose());
			time.setText(order.getTakeTime() + "-" + order.getRetrunTime());
			carType.setText(order.getCar().getCarBrand());
			applayTime.setText(order.getApplyTime());
		} else if (order.getState() == 1) {
			v = LayoutInflater.from(context).inflate(
					R.layout.enterpriseorder_item, null);
			TextView orderId = (TextView) v.findViewById(R.id.orderid);
			ImageView img = (ImageView) v.findViewById(R.id.carimg);
			TextView carBrand = (TextView) v.findViewById(R.id.carbrand);
			TextView plate = (TextView) v.findViewById(R.id.plate);
			TextView takeTime = (TextView) v.findViewById(R.id.taketime);
			TextView returntime = (TextView) v.findViewById(R.id.returntime);
			LinearLayout ll_detail = (LinearLayout) v.findViewById(R.id.ll_detail);
			ll_detail.setOnClickListener(new OnClickListener() {
				
				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
				Intent intent = new Intent(context, PersonalDetailActivity.class);
				context.startActivity(intent);
				}
			});
			Button bt_out = (Button) v.findViewById(R.id.outcar);
			Button bt_cancleApplay = (Button) v
					.findViewById(R.id.cancle_applay);
			bt_cancleApplay.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					EnterpriseAllFragment.tv_cancle.setText("确定要取消订单吗？");
					EnterpriseAllFragment.ll_cancle
							.setVisibility(View.VISIBLE);
				}
			});
			bt_out.setOnClickListener(new OnClickListener() {

				@Override
				public void onClick(View v) {
					// TODO Auto-generated method stub
					Intent intent = new Intent(context,
							EnterpriseOrderActivity.class);
					intent.putExtra("num", 3);
					context.startActivity(intent);
					((Activity) context).finish();
				}
			});
			orderId.setText("订单：SQ-000" + order.getOrderId());
			img.setImageResource(order.getCar().getImg());
			carBrand.setText(order.getCar().getCarBrand());
			plate.setText(order.getCar().getPlate());
			takeTime.setText(order.getTakeTime());
			returntime.setText(order.getRetrunTime());
		}
		return v;
	}

}
